﻿@{
    ViewBag.Title = "SelectOrganizePerson";
    Layout = null;
}

<script type="text/javascript">
    /*左侧树*/
    var Permission_Organize_tree = {
        _TreeUrl: "/Permission/Organize/GetOrganizeNodes/0",  //获取节点数据的URL地址
        init: function () {
            this.BindTree();
        },
        BindTree: function () {
            $("#SelectOrganizePerson_LeftBar_Tree").zTree(
        {
            checkable: false,
            async: true,
            isSimpleData: true,
            editable: true,
            edit_removeBtn: false,
            edit_renameBtn: false,
            dragCopy: true,
            dragMove: true,
            asyncUrl: this._TreeUrl,  //获取节点数据的URL地址        
            nameCol: "Name",
            open: false,
            treeNodeKey: "Id",
            treeNodeParentKey: "ParentId",
            callback: {
                click: this.Select
            }
        }, null);
        },
        getSelectedNode: function () {
            return $("#treeID").val();
        }
    , Select: function (event, treeId, treeNode) {
        $("#treeID").val(treeNode.Type_ID);
      
//        var TreeLink = $("#treeIDLink").val();
//        if (TreeLink == "0") {
//            Book_Index_Grid.reload();
//            $("#Book_Index_Add").attr("href", "/Books/Book/Edit/?classID=" + $("#treeID").val());
//        }
    },
        Save: function (json) {
            DWZ.ajaxDone(json);
            if (json.statusCode == DWZ.statusCode.ok) {
                //this.BindTree();
                Permission_Organize_tree.init();
                $.pdialog.closeCurrent();
            }
        },
        realoadTree: function () {
            $("#treeModule_StorageManage_StorageClass_index").zTree(this.BindTree, "");
        }
    };
    /*右侧列表*/
var Permission_Organize_Grid = {
_GridHeight : GridHeight,
 _GridTable : "Book_Index_RightBar_Table",
 _GridPage :"Book_Index_RightBar_Table_Page",
 _keyID :"BookInfo_ID",
 _DelUrl : "/Books/Book/Delete",
 _EditUrl : "/Books/Book/Edit",
_SourceUrl : "/Books/Book/PageList/?type=0",
    init:function(){
         this.GridGet();
    },
    GridGet: function () {
        $("#" +this._GridTable).jqGrid({
            url:this._SourceUrl, datatype: "json", mtype: "post",
            colNames: ['id', '资料名称', '所属分类', '作者', '出版社', '借阅状态','', '剩余量（本）', '库存总量（本）', '登记时间','操作'],
            colModel: [
                { name: 'BookInfo_ID', index: 'BookInfo_ID', width: 20, align: "center", sortable: false, hidden: true },
                { name: 'BookInfo_Name', index: 'BookInfo_Name', width: 20, align: "center", sortable: false, hidden:false,formatter:this.DoDetail },
                { name: 'BookInfo_TypeName', index: 'BookInfo_TypeName', width: 20, align: "center", sortable: false, hidden: false },
                { name: 'BookInfo_Author', index: 'BookInfo_Author', width: 20, align: "center", sortable: false, hidden: false },
                { name: 'BookInfo_Publishers', index: 'BookInfo_Publishers', width: 20, align: "center", sortable: false, hidden: false },

                { name: 'BookInfo_Publishers', index: 'BookInfo_Publishers', width: 20, align: "center", sortable: false, hidden: false,formatter:this.DoStatus },
                { name: 'BookInfo_ResidueCount', index: 'BookInfo_ResidueCount', width: 20, align: "center", sortable: false, hidden: true },
                { name: 'BookInfo_ViewCount', index: 'BookInfo_ViewCount', width: 20, align: "center", sortable: false, hidden: false,formatter:this.DoStatusColor },
                { name: 'BookInfo_AllCount', index: 'BookInfo_AllCount', width: 20, align: "center", sortable: false, hidden: false },
                { name: 'BookInfo_AddDate', index: 'BookInfo_AddDate', width: 20, align: "center", sortable: false, hidden: false,formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'} },
                { name: '', index: 'BookInfo_AllCount', width: 20, align: "center", sortable: false, hidden: false,formatter:this.DoWork }
             ],
            loadError: function (xhr, status) { alertMsg.error(xhr.responseText); }, loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar"); ajaxbg.hide();
                initUI($("#" + this._GridTable));
            },
            onSelectRow: this.RowSelectEdit,
            rownumbers: true,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            pager:'Book_Index_RightBar_Table_Page',
            rowNum: 20,
            jsonReader: {
                repeatitems: false
            },
            width: '100%',
            height: this._GridHeight - 93
        }).navGrid('#' +this._GridTable, { edit: false, add: false, del: false, refresh: false, search: false });
    },
    ///读取选择行
    GetSelectRow: function () {
        var Role_Jqgrid = $("#" + this._GridTable); var Role_Index_Get_ListID = $("#" +this._GridTable).jqGrid("getGridParam", "selrow"); if (Role_Index_Get_ListID == "") return ""; var Role_Index_ListID = ""; var temp = "";
        temp = Role_Jqgrid.getCell(Role_Index_Get_ListID, this._keyID).toString(); if (temp != "" && temp != "false") { Role_Index_ListID = temp; } return Role_Index_ListID;
    },
    ///行触发事件
    RowSelectEdit: function (rowid, status) {            
        var tempID = $("#Book_Index_RightBar_Table").getCell(rowid, "BookInfo_ID");
        var _LessNum=parseInt($("#Book_Index_RightBar_Table").getCell(rowid,"BookInfo_ResidueCount"));
        var _Num=parseInt($("#Book_Index_RightBar_Table").getCell(rowid, "BookInfo_AllCount"));           
            if ($("#Book_Index_RightBar_Table").jqGrid("getGridParam", "selrow").toString() == "") {
                $("#Book_Index_Edit").attr("href", "/Books/Book/Edit/"+"{sid_user}");
                return;
            }
            else {
                       var _less=_Num-_LessNum;                
                    if(_Num==_LessNum&&_less==0)
                   {                
                      $("#Book_Index_Delete").show();
                   }
                   else{
                    $("#Book_Index_Delete").hide();                   
                   }
                $("#Book_Index_Edit").attr("href","/Books/Book/Edit/"+tempID.toString());
          
                return;
            }        
    }
    /*重新加载*/
    , reload: function () {
        $("#" + this._GridTable).jqGrid("setGridParam", {
            url: this._SourceUrl,
            postData: { "classID":$("#treeID").val(),"searchName": $("#Book_Index_SearchText").val() == "请录入资料名称" ? "" : $("#Book_Index_SearchText").val() },
            datatype: "json"
        }).trigger("reloadGrid");
    },
    DefaultTextVal: function (obj, objVal) { var prjname = $("#" + obj).val(); if (prjname == "") { $("#" + obj).val(objVal); }  $("#" + obj).focus(function () { if ($(this).val() == objVal) $(this).val(""); }).blur(function () { if ($(this).val().length == 0) $(this).val(objVal); }); },
   
};
    /*调用*/
    $(function () {
        Permission_Organize_tree.init();
    //    Permission_Organize_Grid.init();
    });
</script>
<div id="Book_Index_LeftBar" style="float: left; overflow: auto; width: 240px; border: solid #e6e6e6;
    border-width: 1px 1px 0 0; line-height: 21px; background: #fff;" layouth="32">
       <div class="panel">
        <h1>
            职位</h1>
        <input id="treeID" value="0" type="hidden" />
        <input id="treeIDLink" value="0" type="hidden" />
        <div>
            <ul id="SelectOrganizePerson_LeftBar_Tree" class="ztree">
            </ul>
            <input name="folderID" id="folderID" value="0" type="hidden" />
        </div>
    </div>
</div>
<div class="pageFormContent" style="border-style: none;">    
    <table id="SelectOrganizePerson_Table" />
    <div id="SelectOrganizePerson_Table_Page" />
</div>